﻿/*
 * Crée par SharpDevelop.
 * Utilisateur: Propriétaire
 * Date: 21/01/2012
 * Heure: 09:21
 * 
 * Pour changer ce modèle utiliser Outils | Options | Codage | Editer les en-têtes standards.
 */
using System;
using System.Drawing;
using System.Windows.Forms;
//using System.Diagnostics;
//using System.Media;
//using System.Collections.Generic;

namespace IPD_GeneralLib
{
    /// <summary>
    /// Description of Affiche_enreg.
    /// </summary>
public partial class Affiche_enregContacts : Form
 {
  
    internal static int AFFENRindexenreg = -1 ;
    internal static int AFFENRmaxnumenreg = -1 ;
    
    private static bool bIncomboautoselect = false ;

    
public Affiche_enregContacts()
    {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();
            
            //
            // TODO: Add constructor code after the InitializeComponent() call.
            //
        }
		
void Affiche_enregContactsLoad(object sender, EventArgs e)
 {
  this.Text += " Contacts" ;
 
  adaptObjectsForm2DataBaseType() ;
  displaycontacts() ;
}

void adaptObjectsForm2DataBaseType()
 {
   int jj = 0 ;
   comboBox1.Items.Clear() ;
   for (int ii = 0 ; ii < AFFENRmaxnumenreg ; ii++)
      {
        jj = ii + 1 ;
        comboBox1.Items.Add(jj.ToString("0000")) ;
     }
}

void displaycontacts()
 {
// CONTACT_ColFirstName, CONTACT_ColLastName, CONTACT_ColHomeAddress1, CONTACT_ColHomeAddress2,  
// CONTACT_ColHomeCity, CONTACT_ColHomeState, CONTACT_ColHomeZIP, CONTACT_ColHomeCountry,  
// CONTACT_ColWorkAddress1, CONTACT_ColWorkAddress2, CONTACT_ColWorkCity, CONTACT_ColWorkState,  
// CONTACT_ColWorkZIP, CONTACT_ColWorkCountry, CONTACT_ColEmail, CONTACT_ColCompany,  
// CONTACT_ColJob, CONTACT_ColWebPage, CONTACT_ColTitle, CONTACT_ColCategories,  
// CONTACT_ColPhoneWork, CONTACT_ColPhoneWork2, CONTACT_ColPhoneHome, CONTACT_ColPhoneHome2,  
// CONTACT_ColPhoneMobile, CONTACT_ColPhoneMobile2, CONTACT_ColPager, CONTACT_ColPIN,  
// CONTACT_ColPhoneOther, CONTACT_ColHomeFax, CONTACT_ColWorkFax, CONTACT_ColUser1,  
// CONTACT_ColUser2, CONTACT_ColUser3, CONTACT_ColUser4, CONTACT_ColBirthday,  
// CONTACT_ColAnniversary, CONTACT_ColNotes

// TextBox and Labels 500 -> 599

   textBox500.Text = IPD_GeneralLib.IPDGeneral.VirtualArray_Contacts[AFFENRindexenreg, IPD_GeneralLib.IPDGeneral.CONTACT_ColFirstName] ;
   textBox501.Text = IPD_GeneralLib.IPDGeneral.VirtualArray_Contacts[AFFENRindexenreg, IPD_GeneralLib.IPDGeneral.CONTACT_ColLastName] ;
   textBox502.Text = IPD_GeneralLib.IPDGeneral.VirtualArray_Contacts[AFFENRindexenreg, IPD_GeneralLib.IPDGeneral.CONTACT_ColPhoneMobile] ;
   textBox503.Text = IPD_GeneralLib.IPDGeneral.VirtualArray_Contacts[AFFENRindexenreg, IPD_GeneralLib.IPDGeneral.CONTACT_ColBirthday] ;
   textBox504.Text = IPD_GeneralLib.IPDGeneral.VirtualArray_Contacts[AFFENRindexenreg, IPD_GeneralLib.IPDGeneral.CONTACT_ColAnniversary] ;
   textBox505.Text = IPD_GeneralLib.IPDGeneral.VirtualArray_Contacts[AFFENRindexenreg, IPD_GeneralLib.IPDGeneral.CONTACT_ColCategories] ;
   
   textBox506.Text = IPD_GeneralLib.IPDGeneral.VirtualArray_Contacts[AFFENRindexenreg, IPD_GeneralLib.IPDGeneral.CONTACT_ColPhoneHome] ;
   textBox507.Text = IPD_GeneralLib.IPDGeneral.VirtualArray_Contacts[AFFENRindexenreg, IPD_GeneralLib.IPDGeneral.CONTACT_ColPhoneWork] ;
   textBox508.Text = IPD_GeneralLib.IPDGeneral.VirtualArray_Contacts[AFFENRindexenreg, IPD_GeneralLib.IPDGeneral.CONTACT_ColPhoneOther] ;
   textBox509.Text = IPD_GeneralLib.IPDGeneral.VirtualArray_Contacts[AFFENRindexenreg, IPD_GeneralLib.IPDGeneral.CONTACT_ColWorkFax] ;
   textBox510.Text = IPD_GeneralLib.IPDGeneral.VirtualArray_Contacts[AFFENRindexenreg, IPD_GeneralLib.IPDGeneral.CONTACT_ColEmail] ;
   textBox511.Text = IPD_GeneralLib.IPDGeneral.VirtualArray_Contacts[AFFENRindexenreg, IPD_GeneralLib.IPDGeneral.CONTACT_ColPIN] ;
   
   textBox512.Text = IPD_GeneralLib.IPDGeneral.VirtualArray_Contacts[AFFENRindexenreg, IPD_GeneralLib.IPDGeneral.CONTACT_ColHomeAddress1] ;
   textBox513.Text = IPD_GeneralLib.IPDGeneral.VirtualArray_Contacts[AFFENRindexenreg, IPD_GeneralLib.IPDGeneral.CONTACT_ColHomeAddress2] ;
   textBox514.Text = IPD_GeneralLib.IPDGeneral.VirtualArray_Contacts[AFFENRindexenreg, IPD_GeneralLib.IPDGeneral.CONTACT_ColHomeZIP] ;
   textBox515.Text = IPD_GeneralLib.IPDGeneral.VirtualArray_Contacts[AFFENRindexenreg, IPD_GeneralLib.IPDGeneral.CONTACT_ColHomeCity] ;
   textBox516.Text = IPD_GeneralLib.IPDGeneral.VirtualArray_Contacts[AFFENRindexenreg, IPD_GeneralLib.IPDGeneral.CONTACT_ColHomeState] ;
   textBox517.Text = IPD_GeneralLib.IPDGeneral.VirtualArray_Contacts[AFFENRindexenreg, IPD_GeneralLib.IPDGeneral.CONTACT_ColHomeCountry] ;
   
   textBox518.Text = IPD_GeneralLib.IPDGeneral.VirtualArray_Contacts[AFFENRindexenreg, IPD_GeneralLib.IPDGeneral.CONTACT_ColNotes] ;
   textBox519.Text = IPD_GeneralLib.IPDGeneral.VirtualArray_Contacts[AFFENRindexenreg, IPD_GeneralLib.IPDGeneral.CONTACT_ColUser1] ;
   textBox520.Text = IPD_GeneralLib.IPDGeneral.VirtualArray_Contacts[AFFENRindexenreg, IPD_GeneralLib.IPDGeneral.CONTACT_ColUser2] ;
   textBox521.Text = IPD_GeneralLib.IPDGeneral.VirtualArray_Contacts[AFFENRindexenreg, IPD_GeneralLib.IPDGeneral.CONTACT_ColUser3] ;
   textBox522.Text = IPD_GeneralLib.IPDGeneral.VirtualArray_Contacts[AFFENRindexenreg, IPD_GeneralLib.IPDGeneral.CONTACT_ColUser4] ;

   textBox523.Text = IPD_GeneralLib.IPDGeneral.VirtualArray_Contacts[AFFENRindexenreg, IPD_GeneralLib.IPDGeneral.CONTACT_ColJob] ;
   textBox524.Text = IPD_GeneralLib.IPDGeneral.VirtualArray_Contacts[AFFENRindexenreg, IPD_GeneralLib.IPDGeneral.CONTACT_ColTitle] ;

   textBox525.Text = IPD_GeneralLib.IPDGeneral.VirtualArray_Contacts[AFFENRindexenreg, IPD_GeneralLib.IPDGeneral.CONTACT_ColWorkAddress1] ;
   textBox526.Text = IPD_GeneralLib.IPDGeneral.VirtualArray_Contacts[AFFENRindexenreg, IPD_GeneralLib.IPDGeneral.CONTACT_ColWorkAddress2] ;
   textBox527.Text = IPD_GeneralLib.IPDGeneral.VirtualArray_Contacts[AFFENRindexenreg, IPD_GeneralLib.IPDGeneral.CONTACT_ColWorkZIP] ;
   textBox528.Text = IPD_GeneralLib.IPDGeneral.VirtualArray_Contacts[AFFENRindexenreg, IPD_GeneralLib.IPDGeneral.CONTACT_ColWorkState] ;
   textBox529.Text = IPD_GeneralLib.IPDGeneral.VirtualArray_Contacts[AFFENRindexenreg, IPD_GeneralLib.IPDGeneral.CONTACT_ColWorkCity] ;
   textBox530.Text = IPD_GeneralLib.IPDGeneral.VirtualArray_Contacts[AFFENRindexenreg, IPD_GeneralLib.IPDGeneral.CONTACT_ColWorkCountry] ;

   textBox531.Text = IPD_GeneralLib.IPDGeneral.VirtualArray_Contacts[AFFENRindexenreg, IPD_GeneralLib.IPDGeneral.CONTACT_ColCompany] ;

   if (pictureBox532.Image != null)
      {
       pictureBox532.Image.Dispose();
       pictureBox532.Image = null ;
     }
   if (IPD_GeneralLib.IPDGeneral.iContactsPicture_Imagetype[AFFENRindexenreg] !=
                                                IPD_GeneralLib.IPDGeneral.CIpdImageType_Unknown)
      {
        string sch = IPD_GeneralLib.IPDGeneral.VirtualArray_Contacts[AFFENRindexenreg,
                                                  IPD_GeneralLib.IPDGeneral.CONTACT_ColPicture];
        byte[] ybytes = IPD_GeneralLib.IPDGeneral.getmybytesfromstring(sch,sch.Length);
        
        System.IO.MemoryStream ms = new System.IO.MemoryStream(ybytes);
        pictureBox532.Image = Image.FromStream(ms);
        
        //string stmpfile = @".\~tmpimg1.jpg" ;
        //create_tmpimagefile(ybytes, stmpfile) ;
        //pictureBox532.Image = Image.FromFile(stmpfile);
     }
     
   bIncomboautoselect = true ;
   comboBox1.SelectedIndex = AFFENRindexenreg ;       
   bIncomboautoselect = false ;
}

Image byteArrayToImage(byte[] byteArrayIn)
 {
     System.IO.MemoryStream ms = new System.IO.MemoryStream(byteArrayIn);
     Image returnImage = Image.FromStream(ms);
     return (returnImage);
}

// Next record
void Button3Click(object sender, EventArgs e)
 {
   AFFENRindexenreg += 1 ;
  
   if (AFFENRindexenreg > AFFENRmaxnumenreg - 1)
      {
  	    AFFENRindexenreg = AFFENRmaxnumenreg - 1 ;
  	    return ;
     }
  
  displaycontacts() ;
}
        
// Previous record
void Button2Click(object sender, EventArgs e)
 {
   AFFENRindexenreg -= 1 ;
  
   if (AFFENRindexenreg < 0)
     {
      AFFENRindexenreg = 0 ;
      return ;
    }

  displaycontacts() ;
}
        
// Goto last record
void Button4Click(object sender, EventArgs e)
 {
   if (AFFENRindexenreg == AFFENRmaxnumenreg - 1)
        return ; // already last record
  
   AFFENRindexenreg = AFFENRmaxnumenreg - 1 ;
 
  displaycontacts() ;
}
        
// Goto first record
void Button5Click(object sender, EventArgs e)
 {
   if (AFFENRindexenreg == 0) // Already first record
  	   return ;
  
   AFFENRindexenreg = 0 ;
 
  displaycontacts() ;
}
        
// Close Form
void Button1Click(object sender, EventArgs e)
 {
   Close() ;
}
        
void ComboBox1SelectedIndexChanged(object sender, EventArgs e)
 {
   if (bIncomboautoselect == true)
       return ;

   AFFENRindexenreg = comboBox1.SelectedIndex ;

   bIncomboautoselect = true ;
   displaycontacts() ;
   bIncomboautoselect = false ;
}

void create_tmpimagefile(byte [] yallblock, string stmpfname)
 {

  System.IO.FileStream ws = new System.IO.FileStream(stmpfname, System.IO.FileMode.Create);
  System.IO.BinaryWriter wb = new System.IO.BinaryWriter(ws);
  
  wb.Write(yallblock) ;
  if (wb != null)
     {
      wb.Close() ;
      wb.Dispose();
   }

}

    }
}
